// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   IVL_REALImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.IVL_REAL;
import com.sunwayhorizo.health.hl7.datatypes.QTY;
import com.sunwayhorizo.health.hl7.datatypes.REAL;
import com.sunwayhorizo.health.hl7.datatypes.SET_REAL;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Set;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, CSImpl, NullFlavorImpl, 
//            REALImpl, TYPEImpl

public class IVL_REALImpl extends ANYImpl
    implements IVL_REAL
{

    public static final String RCS_ID = "$Header: IVL_REALImpl.java 115.27 2005/09/16 09:23:19 amchanda noship $";
    protected REAL _low;
    protected REAL _high;
    protected BL _lowClosed;
    protected BL _highClosed;
    protected REAL _center;
    protected REAL _width;
    private static final IVL_REAL nullNI = new IVL_REALImpl(CSImpl.valueOf("NI"));
    private static final IVL_REAL nullOTH = new IVL_REALImpl(CSImpl.valueOf("OTH"));
    private static final IVL_REAL nullNINF = new IVL_REALImpl(CSImpl.valueOf("NINF"));
    private static final IVL_REAL nullPINF = new IVL_REALImpl(CSImpl.valueOf("PINF"));
    private static final IVL_REAL nullUNK = new IVL_REALImpl(CSImpl.valueOf("UNK"));
    private static final IVL_REAL nullASKU = new IVL_REALImpl(CSImpl.valueOf("ASKU"));
    private static final IVL_REAL nullNAV = new IVL_REALImpl(CSImpl.valueOf("NAV"));
    private static final IVL_REAL nullMSK = new IVL_REALImpl(CSImpl.valueOf("MSK"));
    private static final IVL_REAL nullNA = new IVL_REALImpl(CSImpl.valueOf("NA"));
    private static final IVL_REAL nullNASK = new IVL_REALImpl(CSImpl.valueOf("NASK"));

    public static IVL_REAL valueOf(REAL real, BL bl, REAL real1, BL bl1)
    {
        return new IVL_REALImpl(real, bl, real1, bl1);
    }

    public static IVL_REAL nullIVL_REAL()
    {
        return new IVL_REALImpl(null);
    }

    private IVL_REALImpl(REAL real, BL bl, REAL real1, BL bl1)
    {
        if(bl == null || real == null || real1 == null || bl1 == null)
        {
            if(bl == null)
                throw ANYImpl.newNullException("IVL<REAL>", "constructor", "lowClosed");
            if(real == null)
                throw ANYImpl.newNullException("IVL<REAL>", "constructor", "low");
            if(real1 == null)
                throw ANYImpl.newNullException("IVL<REAL>", "constructor", "high");
            if(bl1 == null)
                throw ANYImpl.newNullException("IVL<REAL>", "constructor", "highClosed");
        }
        _lowClosed = bl;
        _low = real;
        _high = real1;
        _highClosed = bl1;
    }

    private IVL_REALImpl(CS cs)
    {
        super(true, cs);
        _low = REALImpl.nullREAL(NullFlavorImpl.NI);
        _high = REALImpl.nullREAL(NullFlavorImpl.NI);
        _lowClosed = BLImpl.nullBL(NullFlavorImpl.NI);
        _highClosed = BLImpl.nullBL(NullFlavorImpl.NI);
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.IVL_REAL;
    }

    public ST literal()
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "literal");
    }

    public REAL low()
    {
        if(isNull().isTrue())
            return REALImpl.nullREAL();
        else
            return _low;
    }

    public REAL high()
    {
        if(isNull().isTrue())
            return REALImpl.nullREAL();
        else
            return _high;
    }

    public BL lowClosed()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return _lowClosed;
    }

    public BL highClosed()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return _highClosed;
    }

    public QTY width()
    {
        if(isNull().isTrue())
            return REALImpl.nullREAL();
        if(_width == null)
            _width = (REAL)_high.minus(_low);
        return _width;
    }

    public REAL center()
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "center");
    }

    public BL contains(REAL real)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return low().lessOrEqual(real).or(low().isNull()).and(real.lessOrEqual(high()).or(high().isNull())).and(low().equal(real).implies(lowClosed())).and(high().equal(real).implies(highClosed()));
    }

    public BL isEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return width().isZero().and(lowClosed().and(highClosed()).not());
    }

    public BL nonEmpty()
    {
        return isEmpty().not();
    }

    public BL notEmpty()
    {
        return isEmpty().not();
    }

    public BL contains(SET_REAL set_real)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        if(set_real instanceof IVL_REAL)
        {
            IVL_REAL ivl_real = (IVL_REAL)set_real;
            return contains(ivl_real.low()).and(contains(ivl_real.high()));
        }
        if(set_real instanceof SET_REAL)
            return contains(((SET_REAL) (set_real.hull())));
        else
            return BLImpl.FALSE;
    }

    public INT cardinality()
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "cardinality");
    }

    public SET_REAL union(REAL real)
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "union");
    }

    public SET_REAL union(SET_REAL set_real)
    {
        if(set_real instanceof IVL_REAL)
        {
            IVL_REAL ivl_real = (IVL_REAL)set_real;
            if(overlaps(ivl_real).isTrue())
                return hull(ivl_real);
        } else
        {
            if(contains(set_real.hull()).isTrue())
                return this;
            if(set_real.contains(this).isTrue())
                return set_real;
        }
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "union");
    }

    public SET_REAL except(REAL real)
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "except");
    }

    public SET_REAL except(SET_REAL set_real)
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "except");
    }

    public SET_REAL intersection(SET_REAL set_real)
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "intersection");
    }

    public IVL_REAL intersection(IVL_REAL ivl_real)
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "intersection");
    }

    public IVL_REAL hull(IVL_REAL ivl_real)
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "hull");
    }

    public BL overlaps(IVL_REAL ivl_real)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return contains(ivl_real.low()).or(contains(ivl_real.high())).or(ivl_real.contains(low())).or(ivl_real.contains(high()));
    }

    public IVL_REAL hull()
    {
        return this;
    }

    public IVL_REAL nextTo(REAL real)
    {
        if(real.lessOrEqual(high()).isTrue())
        {
            if(real.equal(high()).isTrue())
            {
                if(highClosed().isFalse())
                    return this;
                else
                    return nullIVL_REAL();
            } else
            {
                return this;
            }
        } else
        {
            return nullIVL_REAL();
        }
    }

    public IVL_REAL nextAfter(REAL real)
    {
        IVL_REAL ivl_real = nextTo(real);
        if(ivl_real.isNull().isFalse() && ivl_real.contains(real).isFalse())
            return this;
        else
            return nullIVL_REAL();
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof IVL_REAL))
            return BLImpl.FALSE;
        IVL_REAL ivl_real = (IVL_REAL)any;
        if(isNull().or(any.isNull()).isTrue())
            return BLImpl.FALSE;
        else
            return lowClosed().equal(ivl_real.lowClosed()).or(lowClosed().isNull().and(ivl_real.lowClosed().isNull())).and(highClosed().equal(ivl_real.highClosed()).or(highClosed().isNull().and(ivl_real.highClosed().isNull()))).and(low().equal(ivl_real.low()).or(low().isNull().and(ivl_real.low().isNull()))).and(high().equal(ivl_real.high()).or(high().isNull().and(ivl_real.high().isNull())));
    }

    public SET_REAL promotion(REAL real)
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "promotion");
    }

    public REAL demotion()
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "demotion");
    }

    public Set toSet()
    {
        throw ANYImpl.newUnsupportedException("IVL<REAL>", "toSet");
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = (XMLElement)xmldocument.createElement(s);
//            if(low() != null && low().isNull().isFalse())
//                xmlelement.appendChild(((REALImpl)low()).writeXML(xmldocument, "low")[0]);
//            if(high() != null && high().isNull().isFalse())
//                xmlelement.appendChild(((REALImpl)high()).writeXML(xmldocument, "high")[0]);
//            if(width() != null && width().isNull().isTrue())
//                xmlelement.appendChild(((REALImpl)width()).writeXML(xmldocument, "width")[0]);
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static IVL_REAL nullIVL_REAL(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
